/*
 * Phase.h
 *
 *  Created on: 23 May 2011
 *      Author: allan
 */

#ifndef PHASE_H_
#define PHASE_H_

// C++ includes
#include <memory>
#include <string>
#include <vector>
using namespace std;

// Eigen includes
#include <Eigen/Core>
using namespace Eigen;

// GeoReact includes
#include <Core/Activity.h>
#include <Utils/Algorithms.h>

class Phase
{
public:
	Phase();
	
	Phase(const string& name);
	
	Phase(const string& name, const vector<string>& species);
	
	void
	SetName(const string& name);
	
	void
	SetSpecies(const vector<string>& species);
	
	template<class ActivityType> void
	SetSpeciesActivity(const string& species_name, const ActivityType& activity);
	
	const unsigned
	GetNumSpecies() const;
	
	const string
	GetName() const;
	
	const vector<string>&
	GetSpecies() const;
	
	const VectorXd
	MolarFractions(const VectorXd& n) const;
	
	const VectorXd
	Activities(double T, double P, const VectorXd& n) const;
	
	const VectorXd
	ActivityCoefficients(double T, double P, const VectorXd& n) const;
	
	const MatrixXd
	ActivityDerivatives(double T, double P, const VectorXd& n, const VectorXd& a) const;
	
private:
	/// The name of the phase
	string name;
	
	/// The species that compose the phase
	vector<string> species;
	
	/// The activity instance of every species in the phase
	vector<shared_ptr<Activity>> activity_species;
};

template<class ActivityType> void
Phase::SetSpeciesActivity(const string& species_name, const ActivityType& activity)
{
	const unsigned index_species = IndexOf(species_name, species);
	
	if(index_species < species.size())
		activity_species[index_species] = shared_ptr<Activity>(new ActivityType(activity));
}

#endif /* PHASE_H_ */
